package control;

import view.Boundary;
import model.Board;
import model.Player;

public class SetupController {
	
	@SuppressWarnings("unused") // Is needed.
	public void setup(){
		new Board();
		
		if(!Boundary.getYesNo("Do you want to use default values?")){
			Board.initBalance = 
				Boundary.getInt("Set the players initial balance", 
							"The initial balance must be a positive number");
			Board.startBonus = 
				Boundary.getInt("Set the bonus you get when passing start",
							"The start bonus must be a positive number");
			Board.getOutOfJailPrice = 
				Boundary.getInt("Set the price you have to pay to get out of jail",
							"The get out of jail price must be a positive number");
		}
		
		int i = 1;
		for(; i <= 2; i++){
			//			players[i-1] = makePlayer(i);
			String name = getNewName(i);
			Board.players[i-1] = new Player(name.trim(), i-1, Board.initBalance);
			if (i > 1 && Board.players[0].equals(Board.players[1]))	i--;
		}
		while(i <= 6 && Boundary.getYesNo("Do you want to add another player?")){
			boolean nameExists;
			String name;
			do {
				name = getNewName(i);
				nameExists = false;
				for (int j = 0; j < i; j++) {
					if (name.equals(Board.players[j].getName())){
						nameExists = true;
						break;
					}
				}
			} while (nameExists);
			Board.players[i] = new Player(name.trim(), i-1, Board.initBalance);
			
			//			Board.players[i].setPosition(Board.players[i].getPosition()); // Needed to place the player on the board;
			i++;
		}
	}
	private String getNewName(int i){
		String name;
		do {
			name = Boundary.getString("What is the name of player " + i);
		} while(name == null || "".equals(name));
		return name;
	}
	
	
//	private Player makePlayer(int i){
//		String name;
//		do {
//			name = Input.getString("What is the name of player " + i);
//		} while(name == null || "".equals(name));
//		return new Player(name.trim(), i-1, Board.initBalance);
//	}
}
